package com.linln.modules.system.service.impl;

import com.linln.common.data.PageSort;
import com.linln.modules.system.domain.*;
import com.linln.modules.system.repository.*;
import com.linln.modules.system.service.RPatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class RPatientServiceImpl implements RPatientService {

    //患者基本信息
    @Autowired
    RPatientBaseInfoRepository rPatientBaseInfoRepository;

    //患者出生情况
    @Autowired
    RPatientBirthSituationRepository rPatientBirthSituationRepository;

    //患者临床信息
    @Autowired
    RPatientClinicalInformationRepository rPatientClinicalInformationRepository;

    //患者费用信息
    @Autowired
    RPatientCostInformationRepository rPatientCostInformationRepository;

    //患者双亲情况
    @Autowired
    RPatientParentsSituationRepository rPatientParentsSituationRepository;

    //患者个人情况
    @Autowired
    RPatientPersonalSituationRepository rPatientPersonalSituationRepository;

    //患者病案首页费用信息
    @Autowired
    RPatientBaCostInformationRepository rPatientBaCostInformationRepository;

    @Override
    public Page<PatientBaseInfoEntity> getPagePatientBaseList(Example<PatientBaseInfoEntity> example) {
        // 创建分页对象
        PageRequest page = PageSort.pageRequest();
        return rPatientBaseInfoRepository.findAll(example,page);
    }

    @Override
    public PatientBaseInfoEntity getPatientBaseInfoByid(Integer patientID) {
        return rPatientBaseInfoRepository.findById(patientID);
    }

    @Override
    public PatientClinicalInformationEntity getPatientClinicalInfoByBAH(String bah) {
        return rPatientClinicalInformationRepository.findByBah(bah);
    }

    @Override
    public PatientBirthSituationEntity getPatientBirthInfoByBAH(String bah) {
        return rPatientBirthSituationRepository.findByBah(bah);
    }

    @Override
    public PatientParentsSituationEntity getPatientParentsInfoByBAH(String bah) {
        return rPatientParentsSituationRepository.findByBah(bah);
    }

    @Override
    public PatientCostInformationEntity getPatientCostInfoByBAH(String bah) {
        return rPatientCostInformationRepository.findByBah(bah);
    }

    @Override
    public PatientPersonalSituationEntity getPatientPersonalInfoByBAH(String bah) {
        return rPatientPersonalSituationRepository.findByBah(bah);
    }

    @Override
    public PatientBaCostInformationEntity getPatientBaCostInformationByBAHAndCyrq(Integer BAH, Date Cyrq) {
        return rPatientBaCostInformationRepository.findAllByBahAndCyrq(BAH, Cyrq);
    }

    @Override
    public void savePatientBaseInfo(PatientBaseInfoEntity patientBaseInfoEntity) {
        rPatientBaseInfoRepository.save(patientBaseInfoEntity);
    }

    @Override
    public void savePatientClinicalInformation(PatientClinicalInformationEntity patientClinicalInformationEntity) {
        rPatientClinicalInformationRepository.save(patientClinicalInformationEntity);
    }

    @Override
    public void savePatientBirthSituation(PatientBirthSituationEntity patientBirthSituationEntity) {
        rPatientBirthSituationRepository.save(patientBirthSituationEntity);
    }

    @Override
    public void savePatientParentsSituation(PatientParentsSituationEntity patientParentsSituationEntity) {
        rPatientParentsSituationRepository.save(patientParentsSituationEntity);
    }

    @Override
    public void savePatientCostInformation(PatientCostInformationEntity patientCostInformationEntity) {
        rPatientCostInformationRepository.save(patientCostInformationEntity);
    }

    @Override
    public void savePatientPersonalSituation(PatientPersonalSituationEntity patientPersonalSituationEntity) {
        rPatientPersonalSituationRepository.save(patientPersonalSituationEntity);
    }

    @Override
    public void savePatientBACostInformation(PatientBaCostInformationEntity patientBaCostInformationEntity) {
        rPatientBaCostInformationRepository.save(patientBaCostInformationEntity);
    }

    @Override
    public long getPatientCount() {
        return rPatientBaseInfoRepository.count();
    }

    @Override
    public PatientClinicalInformationEntity getPatientClinicalInfoByBAH(String bah, Date cyrq) {
        return rPatientClinicalInformationRepository.findByBahAndCyrq(bah, cyrq);
    }

    @Override
    public PatientBirthSituationEntity getPatientBirthInfoByBAH(String bah, Date cyrq) {
        return rPatientBirthSituationRepository.findByBahAndCyrq(bah, cyrq);
    }

    @Override
    public PatientParentsSituationEntity getPatientParentsInfoByBAH(String bah, Date cyrq) {
        return rPatientParentsSituationRepository.findByBahAndCyrq(bah, cyrq);
    }

    @Override
    public PatientCostInformationEntity getPatientCostInfoByBAH(String bah, Date cyrq) {
        return rPatientCostInformationRepository.findByBahAndCyrq(bah,cyrq);
    }

    @Override
    public PatientPersonalSituationEntity getPatientPersonalInfoByBAH(String bah, Date cyrq) {
        return rPatientPersonalSituationRepository.findByBahAndCyrq(bah, cyrq);
    }

    @Override
    public PatientBaseInfoEntity getPatientBaseInfoByBAHAndCyrq(String bah, Date cyrq) {
        return rPatientBaseInfoRepository.findByBahAndCyrq(bah,cyrq);
    }
}
